//
//  MineTableViewCell.m
//  shanHaiHuiApp
//
//  Created by DS on 2018/3/8.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "MineTableViewCell.h"
@interface MineTableViewCell()

//白色的界面
Strong UIView * whiteView;

Strong UIView * greyView;


//单号
Strong UILabel * oddNum;
//日期
Strong UILabel * dateStr;
Strong UIView * lineView1;
//商品名
Strong UILabel * goodName;
//数量
Strong UILabel * count;
//价钱
Strong UILabel * perMoney;
Strong UILabel * totlaCount;
Strong UILabel * totalMoney;
Strong UIView * lineView2;
//会员
Strong UIImageView * picImageView;
Strong UILabel * memeberLabel;
Strong UILabel * memeberName;
Strong UIView * lineView3;
//营业员
Strong UIImageView * shopImageView;
Strong UILabel * shopLabel;
Strong UILabel *shopName;
Strong UIView * lineView4;

//配送类型
Strong UILabel * dispatchLael;


Strong UIView * lineView5;

Strong UIView * lineView6;



@end
@implementation MineTableViewCell

#pragma mark--Action

- (void)configBtnClick{
    
    if (_getConfigClick) {
        _getConfigClick();
    }
}

#pragma mark -- Init

- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        
        _greyView = [[UIView alloc] init];
        _greyView.backgroundColor = getColor(@"F0F0F0");
        
       // self.backgroundColor = getColor(@"F0F0F0");
        
        _whiteView = [[UIView alloc] init];
        _whiteView.backgroundColor = getColor(whiteColor);
        _whiteView.layer.cornerRadius = 2.0f;
        _whiteView.layer.masksToBounds = YES;
        

        _oddNum = [[UILabel alloc] init];
        _oddNum.font = DEF_FontSize_11;
        _oddNum.textColor = getColor(@"666666");
        _oddNum.textAlignment = NSTextAlignmentLeft;
        _oddNum.text = @"单号: 0121800000535";
        
        _dateStr = [[UILabel alloc] init];
        _dateStr.font = DEF_FontSize_11;
        _dateStr.textColor = getColor(@"666666");
        _dateStr.text = @"2018.1.1  16:28";
        
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = getColor(dividerColor);
        
        _goodName = [[UILabel alloc] init];
        _goodName.font = DEF_FontSize_14;
        _goodName.textColor = getColor(@"323232");
        _goodName.textAlignment = NSTextAlignmentLeft;
        _goodName.numberOfLines = 0;
        _goodName.text = @"八珍礼盒八珍礼盒八珍礼盒八珍礼盒八珍礼盒八珍礼盒八珍礼盒八珍礼盒八珍礼盒八珍礼盒";
        
        _count = [[UILabel alloc] init];
        _count.font = DEF_FontSize_14;
        _count.textColor = getColor(@"323232");
        _count.text = @"×1";
        
        _perMoney = [[UILabel alloc] init];
        _perMoney.font = DEF_FontSize_14;
        _perMoney.textColor = getColor(@"323232");
        _perMoney.text = @"¥49.80";
        
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = getColor(dividerColor);
        
        _totlaCount = [[UILabel alloc] init];
        _totlaCount.font = DEF_FontSize_11;
        _totlaCount.textColor = getColor(@"9E9E9E");
        _totlaCount.text = @"等9件物品";
        
        _totalMoney = [[UILabel alloc] init];
        _totalMoney.font = DEF_FontSize_14;
        _totalMoney.textColor = getColor(@"EC4350");
        _totalMoney.text = @"总计：200.00元";
        
        _lineView3 = [[UIView alloc] init];
        _lineView3.backgroundColor = getColor(dividerColor);
        
        _picImageView = [UIImageView new];
        _picImageView.contentMode = UIViewContentModeScaleAspectFit;
        _picImageView.image = [UIImage imageNamed:@"huiyuanka"];
        
        _memeberLabel = [[UILabel alloc] init];
        _memeberLabel.font = DEF_FontSize_11;
        _memeberLabel.textColor = getColor(@"666666");
        _memeberLabel.text = @"会员";
        
        _memeberName = [[UILabel alloc] init];
        _memeberName.font = DEF_FontSize_11;
        _memeberName.textColor = getColor(@"666666");
        _memeberName.text = @"李强123456";
        
        _lineView4 = [[UIView alloc] init];
        _lineView4.backgroundColor = getColor(dividerColor);
        
        _shopImageView = [UIImageView new];
        _shopImageView.contentMode = UIViewContentModeScaleAspectFit;
        _shopImageView.image = [UIImage imageNamed:@"yiingyeyuan"];
        
        _shopLabel = [[UILabel alloc] init];
        _shopLabel.font = DEF_FontSize_11;
        _shopLabel.textColor = getColor(@"666666");
        _shopLabel.text = @"营业员";
        
        _shopName = [[UILabel alloc] init];
        _shopName.font = DEF_FontSize_11;
        _shopName.textColor = getColor(@"666666");
        _shopName.text = @"王晓明";
        
        _dispatchLael = [[UILabel alloc] init];
        _dispatchLael.text = @"配送类型: 会员配送";
        _dispatchLael.font = DEF_FontSize_11;
        _dispatchLael.textColor = getColor(@"323232");
        
        _configBtn = [[UIButton alloc] init];
        [_configBtn setTitle:@"确认配送" forState:UIControlStateNormal];
        [_configBtn setTitleColor:getColor(@"4E4E4E") forState:UIControlStateNormal];
        _configBtn.titleLabel.font = DEF_FontSize_11;
        _configBtn.layer.borderWidth = 1.0;
        _configBtn.layer.borderColor = getColor(@"4E4E4E").CGColor;
        [_configBtn addTarget:self action:@selector(configBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
        _lineView5 = [[UIView alloc] init];
        _lineView5.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:240 / 255.0f blue:240 / 255.0f alpha:1];
        
        _lineView6 = [[UIView alloc] init];
        _lineView6.backgroundColor = getColor(dividerColor);
        
        _carImageView = [UIImageView new];
        _carImageView.image = [UIImage imageNamed:@"peisongwancheng"];
        _carImageView.contentMode = UIViewContentModeScaleAspectFit;
        _carImageView.hidden = YES;
        
        _comLabel = [[UILabel alloc] init];
        _comLabel.text = @"订单完成";
        _comLabel.font = DEF_FontSize_11;
        _comLabel.textColor = getColor(@"4E4E4E");
        _comLabel.hidden = YES;
        
        [self addSubview:_greyView];
        
        [_greyView addSubview:_whiteView];
        
        
        [_whiteView sd_addSubviews:@[self.oddNum,self.dateStr,self.lineView1,self.goodName,self.count,self.perMoney,self.lineView2,self.totlaCount,self.totalMoney,self.lineView3,self.picImageView,self.memeberLabel,self.memeberName,self.lineView4,self.shopImageView,self.shopLabel,self.shopName,self.dispatchLael,self.configBtn,self.lineView6,self.carImageView,self.comLabel]];
        
        [self layOutFrame];
    }
    return self;
}

- (void)layOutFrame{
    ws(self)
    
    [_greyView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(UNIT_HEIGHT(0));
        make.left.mas_equalTo(UNIT_WIDTH(0));
        make.right.mas_equalTo(UNIT_WIDTH(0));
        make.bottom.mas_equalTo(0);

    }];
    
    [self.whiteView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(UNIT_HEIGHT(13));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.bottom.mas_equalTo(UNIT_HEIGHT(0));

    }];
    
    
    [self.oddNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(26));
        make.top.mas_equalTo(UNIT_HEIGHT(5));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.dateStr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-26));
        make.top.mas_equalTo(UNIT_HEIGHT(5));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.oddNum.mas_bottom).offset(UNIT_HEIGHT(5));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.goodName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.lineView1.mas_bottom).offset(UNIT_HEIGHT(10));
        make.left.mas_equalTo(UNIT_WIDTH(30));
        make.width.mas_equalTo(SCREEN_WIDTH - UNIT_WIDTH(30));
    }];
    
    [self.count mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(30));
        make.top.mas_equalTo(weakself.goodName.mas_bottom).offset(UNIT_HEIGHT(15));
        make.height.mas_equalTo(UNIT_WIDTH(30));
    }];
    
    [self.perMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-30));
        make.height.mas_equalTo(UNIT_WIDTH(30));
        make.top.mas_equalTo(weakself.goodName.mas_bottom).offset(UNIT_HEIGHT(15));
    }];
    
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.count.mas_bottom).offset(UNIT_HEIGHT(10));
        make.left.mas_equalTo(0);
         make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.totlaCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_HEIGHT(30));
        make.top.mas_equalTo(weakself.lineView2.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.totalMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-30));
        make.top.mas_equalTo(weakself.lineView2.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.totalMoney.mas_bottom).offset(UNIT_HEIGHT(10));
        make.left.mas_equalTo(0);
         make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.lineView3.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(30));
        make.width.mas_equalTo(UNIT_WIDTH(23));
        make.height.mas_equalTo(UNIT_HEIGHT(23));
    }];
    
    [self.memeberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.picImageView.mas_right).offset(UNIT_WIDTH(13));
        make.centerY.mas_equalTo(weakself.picImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.memeberName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-30));
        make.centerY.mas_equalTo(weakself.picImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.picImageView.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(0);
         make.right.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
    
    [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.lineView4.mas_bottom).offset(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(30));
        make.width.mas_equalTo(UNIT_WIDTH(23));
        make.height.mas_equalTo(UNIT_HEIGHT(23));
    }];
    
    [self.shopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.shopImageView.mas_right).offset(UNIT_WIDTH(13));
        make.centerY.mas_equalTo(weakself.shopImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.shopName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-30));
        make.centerY.mas_equalTo(weakself.shopImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.lineView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(UNIT_HEIGHT(1));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(weakself.shopName.mas_bottom).offset(UNIT_HEIGHT(10));
    }];
    
    [self.dispatchLael mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(weakself.lineView6.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.configBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.lineView6.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.width.mas_equalTo(UNIT_WIDTH(80));
    }];
    
    [self.comLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.top.mas_equalTo(weakself.lineView6.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.carImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakself.comLabel.mas_left).mas_offset(UNIT_WIDTH(-10));
        make.centerY.mas_equalTo(weakself.comLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(21));
        make.width.mas_offset(UNIT_WIDTH(21));
        
    }];
    
}

- (void)setModel:(MineDispatchModel *)model{
   
    _model = model;
    
   
    self.oddNum.text = [NSString stringWithFormat:@"单号: %@",model.orderNo];

    NSString *str1 = [NSString stringWithFormat:@"%ld",([model.fDatetime[@"time"] integerValue] / 1000)];
    
    NSString * timeStr = [NSString stringWithFormat:@"%@",[self timeWithTimeIntervalString:str1]];
    self.dateStr.text = timeStr;
    
    self.goodName.text = model.spmc;
    self.count.text  = [NSString stringWithFormat:@"×%@",model.xssl];
    self.perMoney.text = [NSString stringWithFormat:@"¥%@",model.xsje];
    self.totlaCount.text = [NSString stringWithFormat:@"等%@件商品",model.orderDetailrows];
    self.totalMoney.text = [NSString stringWithFormat:@"总计 : %@元",model.orderXsje];
    self.memeberName.text = model.fName;
    self.shopName.text = model.userid;
    
    if ([model.diststatus isEqualToString:@"0"]) {
        
        self.carImageView.hidden = YES;
        self.configBtn.hidden = NO;
        self.comLabel.hidden = YES;
        
    }else{
        
        self.carImageView.hidden = NO;
        self.configBtn.hidden = YES;
        self.comLabel.hidden = NO;
        
    }
    
    
    
    if ([model.disttype isEqualToString:@"mem0"]) {
        self.dispatchLael.text = @"配送类型: 会员配送";
        
    }else if ([model.disttype isEqualToString:@"mem1"]){
        
        self.dispatchLael.text = @"配送类型: 会员自提";
        
        
    }else if ([model.disttype isEqualToString:@"org0"]){
        
        self.dispatchLael.text = @"配送类型: 门店配送";
        
        
    }else{
        
        self.dispatchLael.text = @"配送类型: 门店自提";
        
    }
}


- (NSString *)timeWithTimeIntervalString:(NSString *)timeString
{
    // 格式化时间
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"beijing"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy.MM.dd HH:mm"];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}


@end
